﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

class SearchForWordInFiles
{
    public const string DIR = @"D:\Downloads\Games\UNI\Telerik\NetEssentials\Elian Kurtenkov\1.12_InputOutput\SearchForWordInFiles\Test";

    public static void SearchForString(string str, string rootDir, List<string> results)
    {
        string[] allFiles = Directory.GetFiles(rootDir);
        foreach (string file in allFiles)
        {
            if (file.EndsWith(".txt"))
            {
                using (StreamReader reader = new StreamReader(file))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.Contains(str))
                        { 
                            results.Add(string.Format("{0} : {1}",file,line));
                            break;
                        }
                    }
                }
            }
        }
        string [] allSubDirs = Directory.GetDirectories(rootDir);
        foreach (string dir in allSubDirs)
        {
            SearchForString(str, dir, results);
        }
    }

    static void Main(string[] args)
    {
        List<string> results = new List<string>();
        SearchForString("info", DIR, results);
        foreach (string res in results)
        {
            Console.WriteLine(res);
        }
    }
}
